/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteracon.stack.iterator;

import java.util.Iterator;
import iteracon.stack.EmptyStk;
import iteracon.stack.Stk;

/**
 *
 * @author martin
 */
public final class StkIter<T> implements Iterator<T>{
  private Stk<T> _current;
  
  public StkIter(final Stk<T> s){
    _current=s;
  }
  
  @Override
  public boolean hasNext() {
    return _current.pop()!=EmptyStk.makeStk();
  }

  @Override
  public T next() {
    T tmp = _current.top();
    _current=_current.pop();
    return tmp;
  }

  @Override
  public void remove() {
    throw new UnsupportedOperationException("Stk is immutable");
  }
  
}
